home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / psgui130.zip / PGUIBUT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-01  |  14KB  |  477 lines

  1. {
  2.  
  3.                                                       ╔══════════════════╗
  4.                                                       ║  PGUI Graphic    ║
  5.                                                       ║  Button Include  ║
  6.                                                       ║    Rev.  1.00    ║
  7.                                                       ╚══════════════════╝
  8.  
  9. }
  10.  
  11. Procedure DrwButtonUp(X,Y,Len,Depth,Thickness,Background:Word;
  12.                       Picture:Pointer;Name:String);
  13.  
  14. { ╔════════════════════════════════════════════════════════════════════════╗ }
  15. { ║  Draw Button of Variable Size.                                         ║ }
  16. { ║                                                                        ║ }
  17. { ║  Draw at X,Y with the specified Length, Depth, and Thickness.          ║ }
  18. { ║  The current Background colour must be specified.                      ║ }
  19. { ╚════════════════════════════════════════════════════════════════════════╝ }
  20.  
  21. Var
  22.    Shape:Array[1..8] of Word;
  23.  
  24. Begin
  25.   Mouse.Hide;
  26.   SetFillStyle(SolidFill,LightGray);
  27.   Bar(X,Y,X+Len,Y+Depth-1);
  28.   SetColor(Background);
  29.   Line(X,Y+Depth,X+Len,Y+Depth);
  30.   SetColor(Black);
  31.   SetFillStyle(Solidfill,White);
  32.   Shape[1] := X;
  33.   Shape[2] := Y;
  34.   Shape[3] := X+Len;
  35.   Shape[4] := Y;
  36.   Shape[5] := X+Len-Thickness;
  37.   Shape[6] := Y+Thickness;
  38.   Shape[7] := X+Thickness;
  39.   Shape[8] := Y+Thickness;
  40.   FillPoly(4,Shape);
  41.   Shape[1] := X;
  42.   Shape[2] := Y;
  43.   Shape[3] := X;
  44.   Shape[4] := Y+Depth;
  45.   Shape[5] := X+Thickness;
  46.   Shape[6] := Y+Depth-Thickness;
  47.   Shape[7] := X+Thickness;
  48.   Shape[8] := Y+Thickness;
  49.   FillPoly(4,Shape);
  50.   SetFillStyle(solidfill,DarkGray);
  51.   Shape[1] := X;
  52.   Shape[2] := Y+Depth;
  53.   Shape[3] := X+Len;
  54.   Shape[4] := Y+Depth;
  55.   Shape[5] := X+Len-Thickness;
  56.   Shape[6] := Y+Depth-Thickness;
  57.   Shape[7] := X+Thickness;
  58.   Shape[8] := Y+Depth-Thickness;
  59.   FillPoly(4,Shape);
  60.   Shape[1] := X+Len;
  61.   Shape[2] := Y+Depth;
  62.   Shape[3] := X+Len;
  63.   Shape[4] := Y;
  64.   Shape[5] := X+Len-Thickness;
  65.   Shape[6] := Y+Thickness;
  66.   Shape[7] := X+Len-Thickness;
  67.   Shape[8] := Y+Depth-Thickness;
  68.   FillPoly(4,Shape);
  69.   OutTextXY(X+(Len-8*Length(Name)) DIV 2,(Y+(Depth-8) DIV 2)+Thickness-2,Name);
  70.   Mouse.Show;
  71. End;
  72.  
  73. Procedure DrwButtonDown(X,Y,Len,Depth,Thickness:Word;Picture:Pointer;Name:String);
  74.  
  75. { ╔════════════════════════════════════════════════════════════════════════╗ }
  76. { ║  Draw Button of Variable Size Being Pressed.                           ║ }
  77. { ╚════════════════════════════════════════════════════════════════════════╝ }
  78.  
  79. Begin
  80.   Mouse.Hide;
  81.   SetFillStyle(SolidFill,LightGray);
  82.   Bar(X,Y,X+Len,Y+Depth);
  83.   SetFillStyle(Solidfill,DarkGray);
  84.   Bar(X,Y,X+Len,Y+Thickness);
  85.   Bar(X,Y,X+Thickness,Y+Depth);
  86.   SetFillStyle(Solidfill,White);
  87.   Bar(X+Thickness,Y+Thickness,X+Len,Y+Thickness);
  88.   Bar(X+Thickness,Y+Thickness,X+Thickness,Y+Depth);
  89.   SetColor(Black);
  90.   Line(X,Y+Depth,X+Len,Y+Depth);
  91.   Line(X+Len,Y,X+Len,Y+Depth);
  92.   OutTextXY(X+(Len-8*Length(Name))DIV 2+Thickness,Y+(Depth-8) DIV 2+Thickness,Name);
  93.   Mouse.Show;
  94. End;
  95.  
  96. Procedure DrawButtonUp(X1,Y1,X2,Y2,Thickness,Background:Word;Picture:Pointer;Name:String);
  97.  
  98. { ╔════════════════════════════════════════════════════════════════════════╗ }
  99. { ║  Draw Button of Variable Size.                                         ║ }
  100. { ╚════════════════════════════════════════════════════════════════════════╝ }
  101.  
  102. Begin
  103.   DrwButtonUp(X1,Y1,X2-X1+1,Y2-Y1+1,Thickness,Background,Picture,Name);
  104. End;
  105.  
  106. Procedure DrawButtonDown(X1,Y1,X2,Y2,Thickness:Word;Picture:Pointer;Name:String);
  107.  
  108. { ╔════════════════════════════════════════════════════════════════════════╗ }
  109. { ║  Draw Button of Variable Size Being Pressed.                           ║ }
  110. { ╚════════════════════════════════════════════════════════════════════════╝ }
  111.  
  112. Begin
  113.   DrwButtonDown(X1,Y1,X2-X1+1,Y2-Y1+1,Thickness,Picture,Name);
  114. End;
  115.  
  116. Procedure ButtonChain.Init;
  117. Begin
  118.   Root     :=NIL;
  119.   Total    :=0;
  120.   Buttons  :=NIL;
  121. End;
  122.  
  123. Function ButtonChain.Position:Word;
  124.  
  125. Var
  126.   B     :Pointer;
  127.   X     :Word;
  128.  
  129. Begin
  130.   X:=1;
  131.   B:=Buttons;
  132.   Buttons:=Root;
  133.  
  134.   While (Buttons<>NIL) And (Buttons^.Next<>NIL) And (B<>Buttons) do
  135.   Begin
  136.     Inc(X);
  137.     Buttons:=Buttons^.Next;
  138.   End;
  139.  
  140.   If (B<>Buttons) Or (B=NIL) Then Position:=0;
  141.   Buttons:=B;
  142. End;
  143.  
  144. Function ButtonChain.Number:Word;
  145. Begin
  146.   If Buttons=NIL Then
  147.     Number:=0
  148.   Else
  149.     Number:=Buttons^.Number;
  150. End;
  151.  
  152. Procedure ButtonChain.GotoPosition(Here:Word);
  153.  
  154. Var
  155.   X     :Word;
  156.  
  157. Begin
  158.   If Here=0 Then
  159.   Begin
  160.     Buttons:=NIL;
  161.     Exit;
  162.   End;
  163.  
  164.   X:=1;
  165.   Buttons:=Root;
  166.   While (Buttons<>NIL) And (Buttons^.Next<>NIL) And (X<Here) do
  167.   Begin
  168.     Buttons:=Buttons^.Next;
  169.     Inc(X);
  170.   End;
  171. End;
  172.  
  173. Procedure ButtonChain.GotoNumber(ButtonNumber:Word);    {NIL if not found}
  174. Begin
  175.   Buttons:=Root;
  176.   While (Buttons<>NIL) And (ButtonNumber<>Buttons^.Number) do
  177.     Buttons:=Buttons^.Next;
  178. End;
  179.  
  180. Function ButtonChain.NewButtonNumber:Word;
  181.  
  182. Var
  183.   Highest:Word;
  184.  
  185. Begin
  186.   Buttons:=Root;
  187.   Highest:=0;
  188.   While Buttons<>NIL do
  189.   Begin
  190.     Highest:=Buttons^.Number;
  191.     Buttons:=Buttons^.Next;
  192.   End;
  193.   If Highest>65500 Then
  194.   Begin
  195.     Repeat
  196.       Highest:=Random(65499)+1;
  197.       Buttons:=Root;
  198.       While (Buttons<>NIL) And (Highest<>0) do
  199.       Begin
  200.         If Highest=Buttons^.Number Then Highest:=0;
  201.         Buttons:=Buttons^.Next;
  202.       End;
  203.     Until Highest<>0;
  204.     NewButtonNumber:=Highest;
  205.   End
  206.   Else
  207.     NewButtonNumber:=Highest+1;
  208. End;
  209.  
  210. Procedure ButtonChain.Add(X1, Y1, X2, Y2:Word; Thickness,
  211.                           Background:Word;
  212.                           Picture:Pointer; Name:String;
  213.                           Special:Boolean; Key:Char);
  214.  
  215. { ╔════════════════════════════════════════════════════════════════════════╗ }
  216. { ║                                                                        ║ }
  217. { ║   The button is added to the list.  Button coordinates are at X1,Y1    ║ }
  218. { ║   to X2,Y2.  The equivalent key press is in Key.  Special is True      ║ }
  219. { ║   if the key returned if preceeded by a character 0.                   ║ }
  220. { ║                                                                        ║ }
  221. { ║   Background is the background colour, Picture is a possible           ║ }
  222. { ║   Button picture and it returns a the button's number.                 ║ }
  223. { ║                                                                        ║ }
  224. { ╚════════════════════════════════════════════════════════════════════════╝ }
  225.  
  226. Var
  227.   P   :ButtonListPtr;   {New Button}
  228.  
  229. Begin
  230.   New(P);
  231.   P^.X1         :=X1;
  232.   P^.Y1         :=Y1;
  233.   P^.X2         :=X2;
  234.   P^.Y2         :=Y2;
  235.   P^.Thickness  :=Thickness;
  236.   P^.Background :=Background;
  237.   P^.Picture    :=Picture;
  238.   P^.Name       :=Name;
  239.   P^.Number     :=NewButtonNumber;
  240.   P^.Special    :=Special;
  241.   P^.Key        :=Key;
  242.   P^.Next       :=NIL;
  243.  
  244.   GotoPosition(65535);
  245.  
  246.   If Root=NIL Then
  247.   Begin
  248.     Root:=P;
  249.     Buttons:=P;
  250.   End
  251.   Else
  252.   Begin
  253.     Buttons^.Next:=P;
  254.     Buttons:=P;
  255.   End;
  256.   Inc(Total);
  257. End;
  258.  
  259. Procedure ButtonChain.Create(X1, Y1, X2, Y2:Word; Thickness,
  260.                              Background:Word;
  261.                              Picture:Pointer; Name:String;
  262.                              Special:Boolean; Key:Char);
  263.  
  264. { ╔════════════════════════════════════════════════════════════════════════╗ }
  265. { ║   Displays a Button, and adds it to a Linked List of Buttons.          ║ }
  266. { ╚════════════════════════════════════════════════════════════════════════╝ }
  267.  
  268. Begin
  269.   Add(X1,Y1,X2,Y2,Thickness,Background,Picture,Name,Special,Key);
  270.   DrawButtonUp(X1,Y1,X2,Y2,Thickness,Background,Picture,Name);
  271. End;
  272.  
  273. Procedure ButtonChain.WaitForClick(Var X, Y:Word;Var MouseButtons:Byte;
  274.                                    Var Held,Doubled,Special:Boolean; Var Key:Char);
  275.  
  276. { ╔════════════════════════════════════════════════════════════════════════╗ }
  277. { ║                                                                        ║ }
  278. { ║  This procedure will return which of the currently active button